package com.entities;

import java.util.List;


public class Statistics {
	private float wins;
	private float losses;
	private float percentage;
	private float kills;
	private float deaths;
	private float assists;
	private float gold;
	private float last_hits;
	private float denies;
	private float gpm;
	private float xpm;
	private float gold_spent;
	private float hero_damage;
	private float tower_damage;
	private float hero_healing;
	private float level;
	private int totalgames;
	
	public float getWins() {
		return wins;
	}
	public float getLosses() {
		return losses;
	}
	public float getPercentage() {
		return percentage;
	}
	
	public float getKills() {
		return kills;
	}
	public float getDeaths() {
		return deaths;
	}
	public float getAssists() {
		return assists;
	}
	
	public float getGold() {
		return gold;
	}
	public float getLast_hits() {
		return last_hits;
	}
	public float getDenies() {
		return denies;
	}
	public float getGold_spent() {
		return gold_spent;
	}
	public float getHero_damage() {
		return hero_damage;
	}
	public float getTower_damage() {
		return tower_damage;
	}
	public float getHero_healing() {
		return hero_healing;
	}
	
	public int getTotalgames() {
		return totalgames;
	}
	public float getAvgWins() {
		return getAvg(wins);
	}
	public float getAvgLosses() {
		return getAvg(losses);
	}
	public float getAvgPercentage() {
		return getAvg(percentage);
	}
	
	public float getAvgKills() {
		return getAvg(kills);
	}
	public float getAvgDeaths() {
		return getAvg(deaths);
	}
	public float getAvgAssists() {
		return getAvg(assists);
	}
	
	public float getAvgGold() {
		return getAvg(gold);
	}
	public float getAvgLast_hits() {
		return getAvg(last_hits);
	}
	public float getAvgDenies() {
		return getAvg(denies);
	}
	public float getAvgGpm() {
		return getAvg(gpm);
	}
	public float getAvgXpm() {
		return getAvg(xpm);
	}
	public float getAvgGold_spent() {
		return getAvg(gold_spent);
	}
	public float getAvgHero_damage() {
		return getAvg(hero_damage);
	}
	public float getAvgTower_damage() {
		return getAvg(tower_damage);
	}
	public float getAvgHero_healing() {
		return getAvg(hero_healing);
	}
	public float getAvgLevel() {
		return getAvg(level);
	}
	
	private float getAvg(float total) {
	float avg = 0;
		if(totalgames>0){
			avg = total/totalgames;			
		}
		return avg;
	}
	
	public Statistics(List<Match> matchList, String accId) throws Exception{
		wins = 0;
		losses = 0;
		percentage = 0;
		kills = 0;
		deaths = 0;
		assists = 0;
		gold = 0;
		gold_spent = 0;
		hero_damage = 0;
		hero_healing = 0;
		tower_damage = 0;
		level = 0;
		gpm = 0;
		xpm = 0;
		last_hits = 0;
		denies = 0;
		
		for(Match match: matchList){
			if(MatchDetailed.allMatchsDetailed.get(match.getMatch_id())!=null){
				MatchDetailed md = MatchDetailed.allMatchsDetailed.get(match.getMatch_id());
				PlayerDetailed pd = md.getPlayerOfAccId(accId);
				kills += pd.getKills();
				deaths += pd.getDeaths();
				assists += pd.getAssists();
				gold += pd.getGold();
				gold_spent += pd.getGold_spent();
				hero_damage += pd.getHero_damage();
				hero_healing += pd.getHero_healing();
				tower_damage += pd.getTower_damage();
				level += pd.getLevel();
				gpm += pd.getGpm();
				xpm += pd.getXpm();
				last_hits += pd.getLast_hits();
				denies += pd.getDenies();
				if(md.playeroOfAccIdWon(accId)){
					wins++;
				} else {
					losses++;	
				}
				
			}
		}
		totalgames = (int) (wins + losses);
		percentage = getAvg(wins)*100;
		
	}
	
}
